# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=gethsploit
pkgver=3.144778b
pkgrel=3
pkgdesc='Finding Ethereum nodes which are vulnerable to RPC-attacks.'
groups=('blackarch' 'blackarch-scanner')
arch=('any')
url='https://github.com/KarmaHostage/gethspoit'
license=('custom:unknown')
depends=('python2' 'python2-yaml')
makedepends=('git')
source=("$pkgname::git+https://github.com/KarmaHostage/gethspoit.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  sed -i 's|Popen("geth|Popen("gethsploit|g' "$pkgname.py"
}

package() {
  cd $pkgname

  _tools="gethsploit nodesploit"

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md

  rm *.md

  cp -a * "$pkgdir/usr/share/$pkgname/"

  for i in $_tools; do
    cat > "$pkgdir/usr/bin/$i" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 $i.py "\$@"
EOF
    chmod +x "$pkgdir/usr/bin/$i"
  done
}

